import requests,json
from autoTest_brtcApi.utils.log_util import logger
req = requests.session()


class RestClient():
    def __init__(self):
        self.root_url = 'http://192.168.1.9:8899'

    def excute_request(self, method, url, headers, **kwargs):
        logger.info(f"请求的方法是：{method}")
        logger.info(f"请求的url是：\n{self.root_url + url}")
        logger.info(f"请求头是：\n{json.dumps(headers,ensure_ascii=False,indent=2)}")
        logger.info(f"请求的参数是：\n{json.dumps(kwargs,ensure_ascii=False,indent=2)}")


        ## 发送请求
        if method == "POST":
            res_reg = req.post(url=self.root_url + url, headers=headers, **kwargs)
            return res_reg
        elif method == "PUT":
            res_reg = req.put(url=self.root_url + url, headers=headers, **kwargs)
            return res_reg
